<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="用户名">
              <a-input placeholder="请输入"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="状态">
              <a-select placeholder="请选择" default-value="0">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">正常</a-select-option>
                <a-select-option value="2">禁用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary">查询</a-button>
              <a-button style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <s-table
      row-key="_id"
      size="default"
      :columns="columns"
      :data="loadData"
    >

      <a-avatar slot="avatar" slot-scope="text" size="small" :src="text" />
      <span slot="createTime" slot-scope="text">{{ text  }}</span>
      <span slot="action" slot-scope="text, record">
        <a @click="$refs.modal.edit(record)">编辑</a>
        <a-divider type="vertical" />
        <a href="javascript:;">删除</a>
      </span>
    </s-table>

    <table-form ref="modal" @refresh="$refs.table.refresh()"/>
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { fetchList } from '@/api/system/user'
import TableForm from './modules/UserForm'

const columns = [
  { title: '头像', dataIndex: 'avatar', scopedSlots: { customRender: 'avatar' } },
  { title: '昵称', dataIndex: 'nickname' },
  { title: '账号', dataIndex: 'username' },
  { title: '创建时间', dataIndex: 'createTime', scopedSlots: { customRender: 'createTime' }, sorter: true },
  { title: '操作', width: '150px', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
]

export default {
  name: 'UserList',
  components: {
    STable, TableForm
  },
  data () {
    return {
      visible: false,
      permissions: [],
      // 查询参数
      queryParam: {},
      // 表头
      columns,
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return fetchList(parameter)
          .then(res => {
            console.log('getUserList', res)
            return res.result
          })
      },
    }
  },
  methods: {
  }
}
</script>
